<?php
class News_AjaxController extends Clu_Controller_Action_Hvn
{
	public $m, $mArticle;
	
	public function init()
	{
		//require_once (APP_PATH.'/modules/article/Model/Article.php');
		$this->mArticle = new article_Model_Service();
		$this->m = new Model_News();
		parent::init();
	}
	
	public function deleteNewsAction()
	{
    	$id = $this->_request->getParam('id');
    	if($this->_request->isXmlHttpRequest())
		{
			$db = $this->db;
    	    $ret = array();
    	    //check permission
		    if (strpos ($sess->userPermissions, 'administer user') === false)
			{
				$ret['success'] = false;
				$ret['message'] = t(414);
				$this->_helper->json->sendJson($ret);
				exit();
			}
			
            if ($this->m->deleteByPrimary(array($id), true))
            	$ret['success'] = true;
            else
            	$ret['success'] = false;
            	 
			$this->_helper->json->sendJson($ret);
		}
	}
	
	public function bulkNewsAction()
    {	
    	if($this->_request->isXmlHttpRequest())
		{
        	$ids = $this->_request->getParam('news_ids');
        	//check permission
		    if (strpos ($sess->userPermissions, 'administer user') === false)
			{
				$ret['success'] = false;
				$ret['message'] = t(414);
				$this->_helper->json->sendJson($ret);
				exit();
			}
        	$ret['ids'] = $ids;
        	if (count($ids) > 0)
        	{
            	$action = $this->_request->getParam('bulkaction');
                if ($action === 'delete')
                {
                    if ($this->m->deleteByPrimary($ids))
    					$ret['success'] = true;
                }
                else if($action === 'status')
            	{
                	$ret['status'] = $this->_request->getParam('changestatus');
    				if ($this->m->bulkUpdateStatus($ids, $ret,true))
    				  	$ret['success'] = true;       
                }
        	}
        	else
        		$ret['success'] = false;
        	$ret['bulkaction'] = $action;
        	$this->_helper->json->sendJson($ret);
		}
    }
}
?>